<?php

/**
 * @author Salvador Contreras
 * @copyright 2010
 */

class Model_Log extends Zend_Log
{

	public function writeLog($msg, $priority,$username,$company,$resource,$action,$filter)
	{	

		$extension = ".txt";
		$nombre_archivo = $company.$extension;
		$carpeta_destino = dirname(APPLICATION_PATH . DIAG_PATH. "systemlog" );
		$archivo = $carpeta_destino .DIAG_PATH."systemlog".DIAG_PATH.$nombre_archivo;
		if (file_exists($archivo))

		{
			
		}
		else
		{
			$f = fopen($archivo,"x+");
			fclose($f);	
		}
		$logger = new Zend_Log();
		$writer = new Zend_Log_Writer_Stream($archivo);
		//$filter = new Zend_Log_Filter_Priority (Zend_Log::EMERG);
		$newmsg = $msg.' '.$company.' '.$username.' '.$resource.'/'.$action;
		$logger->addWriter($writer);
		$logger->addFilter($filter);
		$logger->log($newmsg, $priority);
		
					
	}
	
	public function switchLog ($loglevel,$username,$company,$resource,$action)
	{

			switch ($loglevel)
			{
				
				case 1:
				$msg = "Mensaje de depuración";
				$priority = Zend_Log::DEBUG;
				$logger = new Model_Log();
				$filter = new Zend_Log_Filter_Priority (Zend_Log::DEBUG);
				$logger->writeLog($msg,$priority,$username,$company,$resource,$action,$filter);
				break;
				
				case 2:							
				$msg = "Mensaje informativo";
				$priority = Zend_Log::INFO;
				$logger = new Model_Log();
				$filter = new Zend_Log_Filter_Priority (Zend_Log::INFO);
				$logger->writeLog($msg,$priority,$username,$company,$resource,$action,$filter);
				break;
				
				case 3:
				$msg = "Mensaje de advertencia";
				$priority = Zend_Log::WARN;
				$logger = new Model_Log();
				$filter = new Zend_Log_Filter_Priority (Zend_Log::WARN);
				$logger->writeLog($msg,$priority,$username,$company,$resource,$action,$filter);
				break;
				
				case 4:
				$msg = "Mensaje de error";
				$priority = Zend_Log::ERR;
				$logger = new Model_Log();
				$filter = new Zend_Log_Filter_Priority (Zend_Log::ERR);
				$logger->writeLog($msg,$priority,$username,$company,$resource,$action,$filter);
				break;
					
				
			}
		 
	}
}


?>